/* 
 * SearchChecker.java 01.04.2011
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */
package suncertify.util;


/**
 * Helper class to check if criterias are empty and if they match a record.
 * 
 * @author Alessandra Otterbach
 * 
 */
public class SearchChecker {

    /**
     * Checks, if criteria is empty. No criteria returns true.
     * 
     * @param criteria
     * @return true, if criteria is empty
     */
    public boolean checkCriteriaEmpty(String[] criteria) {
	if (StringUtils.isEmpty(criteria[0])
		&& StringUtils.isEmpty(criteria[1])) {
	    return true;
	}
	return false;
    }

    /**
     * Checks if record and criteria match.
     * 
     * @param criteria
     * @param record
     * @return true if criteria and record matches
     */
    public boolean checkCriteria(String[] criteria, String[] record) {
	if (StringUtils.isNotEmpty(criteria[0])
		&& record[0].startsWith(criteria[0].trim())) {
	    return true;
	} else if (StringUtils.isNotEmpty(criteria[1])
		&& record[1].startsWith(criteria[1].trim())) {
	    return true;
	}
	return false;
    }

}
